package Testdemo3.Test1;

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:周次煜
 * Date: 2024-05-22
 * Time：18:03
 */
public class Test4 {
    public static void main(String[] args) {
        int [] array = {0,1,2,2};
        System.out.println(minCostClimbingStairs(array));
    }

    /**
     * 计算最小步数种类
     * @param n
     * @return
     */

    public static long waysToStep(int n) {
        if(n==1) return 1;

        if(n==2) return 2;

        if(n==3) return 4;

        long[] ret = new long[n+1];

        ret[1]=1;
        ret[2]=2;
        ret[3]=4;




        for(int i = 4; i <= n ; i++) {
            ret[i]=ret[i-1]+ret[i-2]+ret[i-3];
        }

        return ret[n]%10000000;
    }


    public static int minCostClimbingStairs(int[] cost) {
        int n=cost.length;
        if(n == 2) {
            return Math.min(cost[0],cost[1]);
        }

        if(n==3) {
            if(cost[0] + cost[2] > cost[1])
                return cost[1];
        }

        int sum=0;
        for(int i = -1; i+2 <= n-1 ; ) {
            if(cost[i+1] <  cost[i+2]) {
                sum += cost[i+1];
                i++;
            } else {
                sum += cost[i+2];
                i += 2;
            }

        }

        return sum;
    }

}



